<?php
/***********************************************
	This class would generate a thumbnail.
************************************************/
class ThumbnailGenerator {
	private $thumbnail = NULL;
	private $thumbnailWidth = NULL;
	private $thumbnailHeight = NULL;
	
	private $newWidth = NULL;
	private $newHeight = NULL;
	
	private $imageWidth = NULL;
	private $imageHeight = NULL;
	
	/************************************************************/
	
	function __construct($jpegPngOrGifImage, $imageFilePath,
							$imageAttributesArray,
							$thumbnailAttributesArray,
							$newWidth_N_HeightArray
							) {
		$this->thumbnailWidth = $thumbnailAttributesArray['thumbnailWidth'];
		$this->thumbnailHeight = $thumbnailAttributesArray['thumbnailHeight'];
		$this->thumbnail = imagecreatetruecolor($this->thumbnailWidth, $this->thumbnailHeight);
		
		$this->newWidth = $newWidth_N_HeightArray['newWidth'];
		$this->newHeight = $newWidth_N_HeightArray['newHeight'];
		
		$this->imageWidth = $imageAttributesArray['imageWidth'];
		$this->imageHeight = $imageAttributesArray['imageHeight'];
		
		imagecopyresampled($this->thumbnail, $jpegPngOrGifImage,
                   			(0 - ($this->newWidth - $this->thumbnailWidth) / 2),
                   			(0 - ($this->newHeight - $this->thumbnailHeight) / 2),
                   			0, 0,
                   			$this->newWidth, $this->newHeight,
                   			$this->imageWidth, $this->imageHeight);

		if (imagejpeg($this->thumbnail, $imageFilePath, 100)) {
			imagejpeg($this->thumbnail, $imageFilePath, 100);
		} elseif (imagepng($this->thumbnail, $imageFilePath, 100)) {
			imagepng($this->thumbnail, $imageFilePath, 100);
		} elseif (imagegif($this->thumbnail, $imageFilePath, 100)) {
			imagegif($this->thumbnail, $imageFilePath, 100);
		}
	}
}
?>